package com.victor.controller.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.victor.entity.PoiSubmit;
import com.victor.service.PoisubmitService;
import com.victor.utils.Msg;
@RestController
@RequestMapping("/apppoi")
public class PoisubmitController {

	@Autowired
	private PoisubmitService poiService;
	
	
	/**
	 * 添加poi点
	 * @param poiSubmit
	 * @return
	 */
	@RequestMapping("/addpoi")
	public Msg poiSubmit(@RequestBody PoiSubmit poiSubmit) {
		if (poiSubmit.getJqid()== null || poiSubmit.getJqid().isEmpty() || poiSubmit.getUid()== null || poiSubmit.getUid().isEmpty()) {
			return Msg.fail("入参错误");
		}
		boolean b = poiService.addPoi(poiSubmit);
		if (!b) {
			return Msg.fail("插入poi失败");
		}
		if (poiSubmit.getList() != null || poiSubmit.getList().size()>0) {
			for (int i = 0; i < poiSubmit.getList().size(); i++) {
				poiSubmit.getList().get(i).setPsid(String.valueOf(poiSubmit.getId()));
				boolean photo = poiService.insertPoiPhoto(poiSubmit.getList().get(i));
				if (!photo) {
					return Msg.fail("插入poi图片失败");
				}
			}
		}
		return Msg.success();
	}
}
